import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue'), redirect:'/welcome',
    children:[
      {
        path: '/index',
        name: 'index',
        component: () => import('../views/index.vue'),
      },
      {
    
        path: '/user',
        name: 'user',
        component: () => import('../components/user/bred'),
        meta:{
          bread:['用户管理','用户列表']
        }
      },
      {
        path: '/jurisdiction',
        name: 'jurisdiction',
        component: () => import('../components/jurisdiction/jurisdiction')
      },{
        path: '/roles',
        name: 'roles',
        component: () => import('../components/power/roles')
      },
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 挂载路由导航守卫
router.beforeEach((to,from,next) =>{
  if(to.path === '/login') return next()
 const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})
export default router
